package com.west.xu.provider.util;

import java.math.BigDecimal;

public class NumberUtils {

    /**
     * 阶乘计算公式
     *
     * @param a
     * @return 返回a的阶乘   a!
     */
    public static BigDecimal jiec(long a) {
        BigDecimal t_a = new BigDecimal(1);
        for (int i = 1; i <= a; i++) {
            t_a = t_a.multiply(new BigDecimal(i));
        }
        return t_a;
    }

    /**
     * 组合计算公式
     *
     * @param up
     * @param down
     * @return 返回 C(down,up)
     */
    public static long zuhe(int up, int down) {
        long t_a = 0;
        t_a = (jiec(down).divide((jiec(down - up).multiply(jiec(up))))).longValue();
        return t_a;
    }
}
